package com.gct.controller;

import java.util.LinkedList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.gct.controller.base.BaseController;
import com.gct.domain.Album;
import com.gct.domain.Art;
import com.gct.domain.wrapper.DomainWrapper;
import com.gct.service.AlbumService;

/*
 * PlayList Page
 */
@RestController
@RequestMapping("/album")
public class AlbumController extends BaseController {
    @Autowired
    private AlbumService albumService;

    // /*
    // * newest 100 Albums
    // */
    // @RequestMapping(value = "/newestalbums",method = RequestMethod.GET,
    // produces = MediaType.APPLICATION_JSON_VALUE)
    // public @ResponseBody List<Album<Art>> topAlbums() {
    // return albumService.topAlbums();
    // }

    @RequestMapping(value = "/albums/{page}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public DomainWrapper<Album<Art>> queryAlbums(@PathVariable("page") long page) {
        try {
            DomainWrapper<Album<Art>> dmw = new DomainWrapper<Album<Art>>();
            dmw.setData(albumService.topAlbums());
            return dmw;
        } catch (Throwable e) {
            return this.<Album<Art>>processException(e);
        }
    }

    @RequestMapping(value = "/artsinalbum/{albumId}/{page}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public DomainWrapper<Album<Art>> artsInAlbum(@PathVariable("albumId") long albumId, @PathVariable("page") long page) {
        try {
            DomainWrapper<Album<Art>> dmw = new DomainWrapper<Album<Art>>();
            List<Album<Art>> arts = new LinkedList<Album<Art>>();
            arts.add(albumService.artsInAlbum(albumId));
            dmw.setData(arts);
            return dmw;
        } catch (Throwable e) {
            return this.<Album<Art>>processException(e);
        }
    }
}
